package com.gy.spark.core.transformations

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Operator_sortBy_sortByKey {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local").setAppName(this.getClass.getSimpleName)
    val sc = new SparkContext(conf)

    val rdd = sc.textFile("spark/input/words.txt")

    val rt: RDD[(String, Int)] = rdd.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _).sortBy(_._2, false, 2)
    rt.foreach(println)

    rdd.flatMap(_.split(" ")).map((1, _)).sortByKey(false).foreach(println)

  }

}
